package com.atguigu03.reflectapply.apply1;

import org.junit.Test;

import java.lang.reflect.Field;

/**
 * ClassName: FieldTest
 * Package: com.atguigu03.reflectapply.apply1
 * Description:
 *
 * @Author BuTang
 * @Create 2023/6/25 9:44
 * @Version 1.0
 */
public class FieldTest {
    @Test
    public void test() throws InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class clazz = User.class;
        //创建实例
        User u = (User) clazz.newInstance();
        Field[] declaredFields = clazz.getDeclaredFields();


        System.out.println("属性的调用");
        Field age = clazz.getField("age");
        age.setAccessible(true);
        age.set(u,27);
        System.out.println(age.get(u));
        System.out.println("属性的调用");


        for (Object a : declaredFields
        ) {


            for (Field f : declaredFields) {
                //1.权限修饰符
                /*
                 * 0x是十六进制
                 * PUBLIC           = 0x00000001;  1    1
                 * PRIVATE          = 0x00000002;  2	10
                 * PROTECTED        = 0x00000004;  4	100
                 * STATIC           = 0x00000008;  8	1000
                 * FINAL            = 0x00000010;  16	10000
                 * ...
                 *
                 * 设计的理念，就是用二进制的某一位是1，来代表一种修饰符，整个二进制中只有一位是1，其余都是0
                 *
                 * mod = 17          0x00000011
                 * if ((mod & PUBLIC) != 0)  说明修饰符中有public
                 * if ((mod & FINAL) != 0)   说明修饰符中有final
                 */

                System.out.println(f.getName());
                System.out.println(f.getModifiers());
                System.out.println(f.getType());
                System.out.println();

            }

        }
    }
}
